package com.benz.project.pvm.controller.role;

import com.benz.project.pvm.controller.BaseController;
import com.benz.project.pvm.domain.Role;
import com.benz.project.pvm.http.param.role.RoleEntity;
import com.benz.project.pvm.http.vo.ResponseEntity;
import com.benz.project.pvm.service.RoleService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/role")
public class GetRoleList extends BaseController {

    @Autowired
    private RoleService roleService;

    @RequestMapping(value="/get_list", method = RequestMethod.POST)
    public ResponseEntity handle(@RequestBody Map<String, Object> params) {
        ResponseEntity responseEntity = new ResponseEntity();
        Long handleStart = System.currentTimeMillis();
        try{
            Map<String, Object> data = new HashMap<String, Object>();
            List<Role> roleList = roleService.getRoles();
            data.put("roles", roleList);
            responseEntity.setData(data);
        }catch(Exception e){
            responseEntity.setError(e.getMessage());
            responseEntity.setMessage("获取角色出错");
            responseEntity.setStatus(500);
        }finally{
            Long handleEnd = System.currentTimeMillis();
            responseEntity.setUseTime(handleEnd - handleStart);
            return responseEntity;
        }
    }
}
